package com.adcok.lcdns.util;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

public class CNCronosLog {
	
	public static final String NameTag = "Cronos";
	public static final int LOG_LEVEL_VERBOSE = 1;
	public static final int LOG_LEVEL_DEBUG = 2;
	public static final int LOG_LEVEL_INFO = 3;
	public static final int LOG_LEVEL_ERROR = 4;
	public static final int LOG_LEVEL_NONE = 5;
	private static int sLogLevel = 1;
	
	public static String getMemoryState()
	{
		Runtime rt = Runtime.getRuntime();
		return "[F_" + (int)rt.freeMemory()/1024 + "/" + (int)rt.totalMemory()/1024 + "]";
	}

	public static int getLogLevel() {
		return sLogLevel;
	}

	public static void setLogLevel(int level) {
		sLogLevel = level;
	}

	public static boolean isLogEnabled() {
		return sLogLevel < 5;
	}

	public static boolean isVerboseLevel() {
		return sLogLevel <= 1;
	}

	public static boolean isDebugLevel() {
		return sLogLevel <= 2;
	}

	public static boolean isInfoLevel() {
		return sLogLevel <= 3;
	}

	public static boolean isErrorLevel() {
		return sLogLevel <= 4;
	}

	public static void e(String msg) {
		if (sLogLevel <= 4) {
			Log.e("Cronos", msg);
		}
	}

	public static void e(String msg, Exception ex) {
		if (sLogLevel <= 4) {
			Log.e("Cronos", msg, ex);
		}
	}

	public static void e(String tag, String msg) {
		if (sLogLevel <= 4) {
			Log.e(tag, msg);
		}
	}

	public static void e(String className, String errorMessage, Exception e) {
		if (sLogLevel <= 4) {
			Log.e("Cronos", "[" + className + "] " + errorMessage, e);
		}
	}

	public static void i(String msg) {
		if (sLogLevel <= 3) {
			Log.i("Cronos", msg);
		}
	}

	public static void i(String tag, String msg) {
		if (sLogLevel <= 3) {
			Log.i(tag, msg);
		}
	}

	public static void d(String tag, String msg) {
		if (sLogLevel <= 2) {
			Log.d(tag, getMemoryState() + " - " + msg);
		}
	}

	public static void d(String msg) {
		if (sLogLevel <= 2) {
			Log.d("Cronos", getMemoryState() + " - " + msg);
		}
	}

	public static void v(String msg) {
		if (sLogLevel <= 1) {
			Log.v("Cronos", getMemoryState() + " - " + msg);
		}
	}

	public static void v(String tag, String msg) {
		if (sLogLevel <= 1) {
			Log.v(tag, msg);
		}
	}

	public static String getStackTraceString(Throwable tr) {
		if (sLogLevel <= 4) {
			return Log.getStackTraceString(tr);
		}

		return "";
	}

	public static void debug_toast(Context context, String msg) {
		if (sLogLevel <= 2) {
			Toast.makeText(context, msg, 0).show();
		}
	}
}